package com.example.barcodeapp.ui.huodong.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.barcodeapp.R;
import com.example.barcodeapp.adapter.FragmentAdapter;
import com.example.barcodeapp.base.BaseActivity;
import com.example.barcodeapp.common.Constants;
import com.example.barcodeapp.interfaces.own.IOwn;
import com.example.barcodeapp.persenter.OnePresenterHuoDongXiangQing;
import com.example.barcodeapp.ui.huodong.Bean.HuoDongXiangQingBean;
import com.example.barcodeapp.ui.huodong.fragment.HuoDongJieShaoFragment;
import com.example.barcodeapp.ui.huodong.fragment.HuoDongXuZhiFragment;
import com.example.barcodeapp.ui.own.activity.QueRenActivity;
import com.example.barcodeapp.ui.wode.bean.WoDHuoDong;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.tabs.TabLayout;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class HuoDongXiangQingActivity extends BaseActivity<IOwn.Persenterkechenghuodongxiangqing> implements IOwn.Viewkechenghuodongxiangqing {


    @BindView(R.id.iv_back_circle)
    ImageView ivBackCircle;
    @BindView(R.id.ff_back_contener)
    FrameLayout ffBackContener;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_location)
    TextView tvLocation;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.ll_to_search)
    LinearLayout llToSearch;
    @BindView(R.id.right_iv)
    ImageView rightIv;
    @BindView(R.id.right_iv_two)
    ImageView rightIvTwo;
    @BindView(R.id.tv_rught_)
    TextView tvRught;
    @BindView(R.id.tv_right_two)
    TextView tvRightTwo;
    @BindView(R.id.toolBar)
    Toolbar toolBar;
    @BindView(R.id.banner2)
    Banner banner2;
    @BindView(R.id.tou)
    LinearLayout tou;
    @BindView(R.id.textView16)
    TextView textView16;
    @BindView(R.id.imageView5)
    ImageView imageView5;
    @BindView(R.id.imageView6)
    ImageView imageView6;
    @BindView(R.id.textView17)
    TextView textView17;
    @BindView(R.id.imageView3)
    ImageView imageView3;
    @BindView(R.id.xilei_kecheng)
    TextView xileiKecheng;
    @BindView(R.id.textView18)
    TextView textView18;
    @BindView(R.id.constraintLayout2)
    ConstraintLayout constraintLayout2;
    @BindView(R.id.textView36)
    TextView textView36;
    @BindView(R.id.textView37)
    TextView textView37;
    @BindView(R.id.tabLayout)
    TabLayout tabLayout;
    @BindView(R.id.appbar)
    AppBarLayout appbar;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.jinru)
    TextView jinru;
    @BindView(R.id.xiangxidizhi)
    TextView xiangxidizhi;
    @BindView(R.id.yibaoming)
    TextView yibaoming;
    private List<HuoDongXiangQingBean.DataEntity> list;

    private ArrayList<Fragment> fragments;
    private FragmentAdapter fragmentAdapter;

    @Override
    protected int getLayout() {
        return R.layout.activity_huo_dong_xiang_qing;
    }

    @Override
    protected void initView() {
        setToolBar(true, false, true, false, false);
        setTitle("热门活动", R.color.black, R.color.white);
        fragments = new ArrayList<>();
        this.fragments.add(new HuoDongJieShaoFragment());
        this.fragments.add(new HuoDongXuZhiFragment());

        fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), this.fragments);
        viewpager.setAdapter(fragmentAdapter);
        tabLayout.setupWithViewPager(viewpager);
        tabLayout.setTabIconTint(null);//显示图片
        tabLayout.getTabAt(0).setText("活动介绍");
        tabLayout.getTabAt(1).setText("须知");

        jinru.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(HuoDongXiangQingActivity.this, ErWeiMaActivity.class);
                intent.putExtra("id",Constants.eriweimaid+"");
                startActivity(intent);
            }
        });

    }

    @Override
    protected OnePresenterHuoDongXiangQing initPersenter() {
        return new OnePresenterHuoDongXiangQing();
    }


    @Override
    protected void initData() {
        persenter.getKeChengHuoDongxiangqing(Constants.huodongxiangqingid,0);
    }


    @Override
    public void getKeChengHuoDongxiangqing(HuoDongXiangQingBean xiLieKeBean) {
        ArrayList<String> list = new ArrayList<>();
        list.add(xiLieKeBean.getData().getHuodong_image());
        banner2.setAdapter(new BannerImageAdapter<String>(list) {
            @Override
            public void onBindView(BannerImageHolder holder, String data, int position, int size) {
                //图片加载自己实现
                Glide.with(holder.itemView)
                        .load(Constants.Base_TPUrl2 + data)
                        .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                        .into(holder.imageView);
            }
        })
                .addBannerLifecycleObserver(this)//添加生命周期观察者
                .setIndicator(new CircleIndicator(this));
        textView16.setText(xiLieKeBean.getData().getHuodong_name());
        textView37.setText(xiLieKeBean.getData().getHuodong_province() + xiLieKeBean.getData().getHuodong_city() + xiLieKeBean.getData().getHuodong_area() + xiLieKeBean.getData().getHuodong_changguan());
        xileiKecheng.setText(xiLieKeBean.getData().getHuodong_type()+"课时");
        textView17.setText(xiLieKeBean.getData().getHuodong_date());
        xiangxidizhi.setText(xiLieKeBean.getData().getHuodong_address_desc());
        yibaoming.setText(xiLieKeBean.getData().getHuodong_price()+"￥");
        yibaoming.setTextColor(this.getResources().getColor(R.color.FFA624));

        Constants.Base_TPUrl3=xiLieKeBean.getData().getHuodong_desc_text();

        Constants.Base_TPUrl43=xiLieKeBean.getData().getXuzhi();
        Constants.eriweimaid=xiLieKeBean.getData().getId();


    }



}